Skip to content

Extract Source trait for flush-thread data sources#408

Merged
rcoh merged 8 commits into
mainfrom
source-trait-extraction
May 18, 2026
Merged

Extract Source trait for flush-thread data sources#408
rcoh merged 8 commits into
mainfrom
source-trait-extraction

Conversation

@rcoh
Copy link
Copy Markdown
Contributor

@rcoh rcoh commented May 15, 2026

Introduce a Source trait that abstracts "thing the flush thread drains into the central collector." CpuProfiler and SchedProfiler now implement Source, and the recorder holds them as Vec<Box<dyn Source>> in SharedState instead of separate typed fields.

This is a pure refactor with no behavior change:

  • The flush loop iterates sources and calls source.flush(&ctx)
  • Worker thread start/stop hooks iterate sources for on_worker_thread_start/stop
  • The trait is pub(crate) and gated behind cfg(feature = "cpu-profiling")

Future data sources (e.g. memory profiler) can implement Source without touching the recorder wiring.

Introduce a `Source` trait that abstracts "thing the flush thread drains
into the central collector." CpuProfiler and SchedProfiler now implement
Source, and the recorder holds them as `Vec<Box<dyn Source>>` in
SharedState instead of separate typed fields.

This is a pure refactor with no behavior change:
- The flush loop iterates sources and calls source.flush(&ctx)
- Worker thread start/stop hooks iterate sources for on_worker_thread_start/stop
- The trait is pub(crate) and gated behind cfg(feature = "cpu-profiling")

Future data sources (e.g. memory profiler) can implement Source without
touching the recorder wiring.
@rcoh rcoh requested a review from a team May 15, 2026 17:59
rcoh added 5 commits May 15, 2026 18:10
ThreadRole is used by the Source trait infrastructure which compiles
unconditionally. Remove the cpu-profiling feature gate so the enum
is always available.
@rcoh rcoh requested a review from yulnr May 18, 2026 13:13
Copy link
Copy Markdown
Collaborator

@yulnr yulnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

nit: this is adding some dead-code warnings (Source trait, FlushContext + fields, methods) when building without cpu-profiling (the trait has no impls without cpu profiling). Can we suppress those somehow? e.g. #[cfg_attr(not(feature="cpu-profiling"), allow(dead_code))] (for now)?

@rcoh rcoh enabled auto-merge May 18, 2026 14:40
@rcoh rcoh added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit baab26f May 18, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants